﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace DungDungShit
{
    abstract class Tile : Sprite
    {
        public Tile(Texture2D defaultTexture, IntVector2 position, IntVector2 frameSize, IntVector2 sheetSize)
            : base(defaultTexture, position, frameSize, sheetSize, false)
        { }

        public abstract bool Enter(NonTile nonTile, IntVector2 nextDirection);
        public abstract bool Slippery();
        public virtual void DrawVelocity(SpriteBatch spriteBatch, SpriteFont spriteFont, Vector2 origin) { }
    }

    class NormalTile : Tile
    {
        public NormalTile(Texture2D defaultTexture, IntVector2 position, IntVector2 frameSize, IntVector2 sheetSize)
            : base(defaultTexture, position, frameSize, sheetSize)
        { }

        public override bool Enter(NonTile nonTile, IntVector2 nextDirection)
        {
            return true;
        }
        public override bool Slippery()
        {
            return false;
        }
        public override string ToString()
        {
            return " ";
        }
    }
    class WallTile : Tile
    {
        public WallTile(Texture2D defaultTexture, IntVector2 position, IntVector2 frameSize, IntVector2 sheetSize)
            : base(defaultTexture, position, frameSize, sheetSize)
        { }

        public override bool Enter(NonTile nonTile, IntVector2 nextDirection)
        {
            return false;
        }
        public override bool Slippery()
        {
            return false;
        }
        public override string ToString()
        {
            return "1";
        }
    }
    class SpikeTile : Tile
    {
        public SpikeTile(Texture2D defaultTexture, IntVector2 position, IntVector2 frameSize, IntVector2 sheetSize)
            : base(defaultTexture, position, frameSize, sheetSize)
        { }
        public bool GivesDamage()
        {
            if (currentFrame.X >= 4 && currentFrame.X <= 11)
                return true;
            return false;
        }
        public override bool Enter(NonTile nonTile, IntVector2 nextDirection)
        {
            return true;
        }
        public override bool Slippery()
        {
            return false;
        }
        public override string ToString()
        {
            return "^";
        }
    }
    class FireTile : Tile
    {
        public FireTile(Texture2D defaultTexture, IntVector2 position, IntVector2 frameSize, IntVector2 sheetSize)
            : base(defaultTexture, position, frameSize, sheetSize)
        { }
        public bool GivesDamage()
        {
            return true;
        }
        public override bool Enter(NonTile nonTile, IntVector2 nextDirection)
        {
            return true;
        }
        public override bool Slippery()
        {
            return false;
        }
        public override string ToString()
        {
            return "$";
        }
    }
    class PersonTile : Tile
    {
        Person person;
        bool isEmpty = false;
        public bool IsEmpty {get {return isEmpty;}}

        public PersonTile(Texture2D defaultTexture, Texture2D personTexture, IntVector2 position, IntVector2 frameSize, IntVector2 sheetSize, int tid)
            : base(defaultTexture, position, frameSize, sheetSize)
        {
            // 0, 1, 2, 3 은 딱 맞은거
            int type = ScreenManager.r.Next(100);
            if (type < 10)
                type = 0;
            else if (type < 35)
                type = 1;
            else if (type < 70)
                type = 2;
            else
                type = 3;
            person = new Person(personTexture, position, frameSize, sheetSize, tid, type);
        }

        public Person RescuePerson()
        {
            isEmpty = true;
            return person;
        }

        public override void Draw(GameTime gameTime, SpriteBatch spriteBatch, Vector2 origin)
        {
            if (!isEmpty)
            {
                person.Draw(gameTime, spriteBatch, origin);
            }
            base.Draw(gameTime, spriteBatch, origin);
        }
        public override bool Enter(NonTile nonTile, IntVector2 nextDirection)
        {
            return true;
        }
        public override bool Slippery()
        {
            return false;
        }
        public override string ToString()
        {
            return "@";
        }
    }
    class EscapeTile : Tile
    {
        public EscapeTile(Texture2D defaultTexture, IntVector2 position, IntVector2 frameSize, IntVector2 sheetSize)
            : base(defaultTexture, position, frameSize, sheetSize)
        { }
        public override bool Enter(NonTile nonTile, IntVector2 nextDirection)
        {
            return true;
        }
        public override bool Slippery()
        {
            return false;
        }
        public override string ToString()
        {
            return "E";
        }
    }
}
